<template>
    <div>
      <h2>请求图书信息</h2>
      <button @click="btnFn">查询</button><br>
      <input v-model="bookName" type="text" name="" id="" placeholder="需要查询的书名"><button @click="inquire">查询</button><br>
      <input v-model="obj.bookname" type="text" placeholder="书名" name="" ><input v-model="obj.author"  type="text" placeholder="作者" name="" ><input  v-model="obj.publisher" type="text" placeholder="出版社" name="" ><br>
      <button @click="addFn">发布</button>
    </div>
</template>

<script>
import axios from 'axios'
export default {
  data(){
    return{
      bookName:"",
      obj:{
        bookname:'',
        author:'',
        publisher:''
      }
    }
  },
  methods:{
    btnFn(){
      axios({
        url:"http://123.57.109.30:3006/api/getbooks",
        method:'get'
      }).then(res=>{
        console.log(res)
      })
    },
    inquire(){
      axios({
        url:"http://123.57.109.30:3006/api/getbooks",
        params:{
          bookname:this.bookName
        }
      }).then(res=>{
        console.log(res)
      }).catch(err=>{
        if(err){
          console.log('错误'+err)
        }
      })
    },
    addFn(){
      axios({
        method:"post",
        url:"http://123.57.109.30:3006/api/addbook",
        data:{
          appkey: "7250d3eb-18e1-41bc-8bb2-11483665535a",
          ...this.obj
        }
      }).then(res=>{
        console.log(res)
      })
    }
  }
}
</script>

<style>

</style>